package com.aaa.service.mht.impl;

import com.aaa.aspect.InsertAnn;
import com.aaa.aspect.UpdateAnn;
import com.aaa.dao.mht.TestPlanMhtDao;
import com.aaa.entity.PageSortEntity;

import com.aaa.entity.mht.TestPlanMht;

import com.aaa.service.mht.TestPlanMhtService;
import com.aaa.utils.RandomSixNumber;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 测试计划fpa(TestPlanMht)表服务实现类
 *
 * @author makejava
 * @since 2022-08-31 19:51:57
 */
@Service("testPlanMhtService")
public class TestPlanMhtServiceImpl implements TestPlanMhtService {
    @Resource
    private TestPlanMhtDao testPlanMhtDao;


    @Override
    public Page queryAll(PageSortEntity pageSortEntity, TestPlanMht testPlanMht) {
        //分页
        PageHelper.startPage(pageSortEntity.getPage(), pageSortEntity.getLimit(), pageSortEntity.getOrderString());
        List<TestPlanMht> testPlanMhts = testPlanMhtDao.queryAll(testPlanMht);
        Page pageResult = (Page) testPlanMhts;
        return pageResult;
    }

    /**
     * 新增数据
     *
     * @param testPlanMht 实例对象
     * @return 实例对象
     */
    @InsertAnn
    @Override
    public boolean insert(TestPlanMht testPlanMht) {
        //生成六位测试码
        Integer six = RandomSixNumber.generateSix();
        testPlanMht.setTestCode(six);
        return testPlanMhtDao.insert(testPlanMht);
    }

    /**
     * 修改数据
     *
     * @param testPlanMht 实例对象
     * @return 实例对象
     */
    @UpdateAnn
    @Override
    public boolean update(TestPlanMht testPlanMht) {
        return testPlanMhtDao.update(testPlanMht);
    }

    /**
     * 通过主键删除数据
     *
     * @return 是否成功
     */
    @Override
    public boolean delete(List list) {
        return testPlanMhtDao.delete(list);
    }

    @Override
    public boolean repetitionName(TestPlanMht testPlanMht) {
        Integer integer = this.testPlanMhtDao.repetitionName(testPlanMht);
        if (integer == 0) {
            return true;
        }
        return false;
    }
}
